package com.LeeCode;

/**
 * 相同的树
 */

public class Code100 {
    public static void main(String[] args) {
        Integer[] arr1 = {1, 2, 3};
        Integer[] arr2 = {1, 2, 8};
        TreeNode p = Utils.buildTree(arr1);
        TreeNode q = Utils.buildTree(arr2);
        System.out.println(new Code100().isSameTree(p, q));
    }

    public boolean isSameTree(TreeNode p, TreeNode q) {
        if (p == null || q == null) return p == q;
        if (p.val != q.val) return false;
        return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
    }
}
